package org.gesplan.util;

import org.jdesktop.beansbinding.Converter;

/**
 * <code>Float</code> to <code>String</code> converter
 * that returns zero when the argument cannot be parsed.
 * 
 * @author David Erill
 */
public class FloatToStringConverter extends Converter<Float, String> {

    @Override
    public String convertForward(Float arg) {
        String aux = String.valueOf(arg);
        return aux;
    }

    @Override
    public Float convertReverse(String arg) {
        float value;
        try {
            arg = arg.replace(",", ".");
            value = (arg == null) ? 0 : Float.parseFloat(arg);
        } catch (NumberFormatException ex) {
            value = -999;
        }
        return value;
    }

    
}